//
//  ThreeCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/12.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "ThreeCell.h"

@implementation ThreeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier segArray:(NSArray *)segArr dataModel:(KeOneModel *)dataModel
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.dataModel = dataModel;
        
        
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.live_area.data) {
            NSLog(@"----===========  %@",fdata.data);
            [dataArr addObject:fdata.data];
        }
        self.countArr = dataArr;
        
        NSLog(@"=====-----    %@",dataArr);
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.live_area.data) {
            NSLog(@"----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        
        
        
        _orageLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
        _orageLab.backgroundColor = [UIColor orangeColor];
        _orageLab.textColor = [UIColor whiteColor];
        _orageLab.font = [UIFont systemFontOfSize:14];
        _orageLab.text = @"   来访客户维度分析";
        [self addSubview:_orageLab];
        
        //分段控件
        _segmented = [[UISegmentedControl alloc] initWithItems:segArr];
        _segmented.selectedSegmentIndex = 0;//设置默认选择项索引
        //  segmented.frame = CGRectMake(20, 300, 250, 20);
        _segmented.tintColor = [UIColor orangeColor];
        //有四种基本样式
        //   [segmented setTitle:@"" forSegmentAtIndex:2];//设置索引的题目
        //   [segmented setImage:[UIImage imageNamed:@""] forSegmentAtIndex:3];//设置指定索引的图片
        [_segmented addTarget:self action:@selector(segmented:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:_segmented];
        [_segmented mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_orageLab.mas_bottom).with.offset(10);
            make.left.equalTo(self).with.offset(10);
            make.right.equalTo(self).with.offset(-10);
            make.height.mas_offset(20);
        }];
        
        
        
        _lineChart = [[ZFLineChart alloc] initWithFrame:CGRectMake(-40, 80,SCREEN_WIDTH+40, 205)];
        //self.lineChart.topicLabel.textColor = ZFBlack;
        self.lineChart.dataSource = self;
        self.lineChart.delegate = self;
        self.lineChart.isResetAxisLineMinValue = YES;
        self.lineChart.isShowXLineSeparate = YES;
        self.lineChart.isShowYLineSeparate = YES;
        self.lineChart.linePatternType = kLinePatternTypeForCurve;
        
        [self addSubview:self.lineChart];
        [self.lineChart strokePath];
        
        
        
        
        
    }
    return self;
}

#pragma mark - ZFGenericChartDataSource

- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
    

    
    return self.countArr;
    
    //return @[@"0", @"20%", @"8.9%", @"20%", @"5%", @"10%"];
}

- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
    
    

    
    return self.nameArr;
    
    //return @[@"一年级", @"二年级", @"三年级", @"四年级", @"五年级", @"六年级"];
}


- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
    //曲线的颜色
    return @[ZFLvColor];
    //return [];
}

- (CGFloat)axisLineMaxValueInGenericChart:(ZFGenericChart *)chart{
    
    if (self.dataModel.focus.max_data) {
        return [self.dataModel.focus.max_data intValue];
    }else{
        return 100;
    }
    
    return 100;
}


//背景格格
- (NSUInteger)axisLineSectionCountInGenericChart:(ZFGenericChart *)chart{
    return 4;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}



//分段控制器
-(void)segmented:(UISegmentedControl *)senge{
    
//    [self.detegate didThreeWithSegmented:senge];
    NSInteger Index = senge.selectedSegmentIndex;
    
    NSLog(@"Index %ld", Index);
    if (Index == 0) {
        
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.live_area.data) {
            NSLog(@"----===========  %@",fdata.data);
            [dataArr addObject:fdata.data];
        }
        self.countArr = dataArr;
        
        NSLog(@"=====-----    %@",dataArr);
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.live_area.data) {
            NSLog(@"----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        NSLog(@"点击的是第1个");
    }else if (Index == 1){
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.zysx.data) {
            NSLog(@"----===========  %@",fdata.data);
            [dataArr addObject:fdata.data];
        }
        self.countArr = dataArr;
        
        NSLog(@"=====-----    %@",dataArr);
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.zysx.data) {
            NSLog(@"----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        NSLog(@"点击的是第2个");
    }else if (Index == 2){
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.order_area.data) {
            NSLog(@"----===========  %@",fdata.data);
            [dataArr addObject:fdata.data];
        }
        self.countArr = dataArr;
        
        NSLog(@"=====-----    %@",dataArr);
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.order_area.data) {
            NSLog(@"----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        NSLog(@"点击的是第3个");
    }else if (Index == 3){
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.focus.data) {
            NSLog(@"----===========  %@",fdata.data);
            [dataArr addObject:fdata.data];
        }
        self.countArr = dataArr;
        
        NSLog(@"=====-----    %@",dataArr);
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataModel *fdata in self.dataModel.focus.data) {
            NSLog(@"----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        NSLog(@"点击的是第4个");
    }else {
        
        NSLog(@"点击的是第6个");
    }
    

    

    
}

@end
